
             
/**
 * 
 *
 * @File name:  TDepartmentDao.java 
 * @Create on:  2011-10-30 19:25:202
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
package com.boho.estates.department.dao;

            
import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.Pager;
            
        /**
 * 【部门信息:T_DEPARTMENT】的Dao操作类
 * 
 */
public class TDepartmentDao extends DAO {
	/**
	* 查询所有【部门信息:T_DEPARTMENT】信息
	* @param con
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static List queryTDepartment(Connection con, String departIds)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where IS_VALID = 1");
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		sql.append(" order by DEPARTMENT_NO desc");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_DEPARTMENT", con);
		return list;
	}
	
	/**
	* 查询所有【部门信息:T_DEPARTMENT】信息
	* @param con
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static List queryTree(Connection con, String departIds)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where IS_VALID = 1");
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		sql.append(" order by DEPARTMENT_NO asc");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_DEPARTMENT", con);
		return list;
	}
	
	public static List queryUserDepartTree(Connection con)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where IS_VALID = 1");
		sql.append(" order by DEPARTMENT_NO asc");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_DEPARTMENT", con);
		return list;
	}
	/**
	* 分页查询所有【部门信息:T_DEPARTMENT】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static ComboPager queryTDepartmentByPager(Connection con,Pager pager, String departmentName)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where IS_VALID = 1 ");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		if(!"".equals(departmentName)){
			sql.append("and lower(DEPARTMENT_NAME) like ?");
			query.setString(1,"%"+departmentName.toLowerCase()+"%");
		}
		sql.append(" order by DEPARTMENT_NO desc");
		query.setCommand(sql.toString());
		return query.getDynaBeanMapComboPager("T_DEPARTMENT", pager,con);
	}
	/**
	* 根据主键【部门编号:DEPARTMENT_NO|】获得信息
	* @param con
	* @param departmentNo 部门编号
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static DynaBeanMap getTDepartmentByPk(Connection con,java.lang.Integer departmentNo)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where DEPARTMENT_NO=? and IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,departmentNo);
		dynaBeanMap = query.getDynaBeanMap("T_DEPARTMENT", con);
		return dynaBeanMap;
	}
	
	/**
	* 根据【部门名称:DEPARTMENT_名称|】获得信息
	* @param con
	* @param departmentNo 部门编号
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static DynaBeanMap getTDepartmentByName(Connection con, String departmentName, String departIds)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DEPARTMENT where DEPARTMENT_NAME=? and IS_VALID = 1");
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1,departmentName);
		dynaBeanMap = query.getDynaBeanMap("T_DEPARTMENT", con);
		return dynaBeanMap;
	}
	
	/**
	 * 
	 * @param con
	 * @param rolename
	 * @param roleid
	 * @return
	 * @throws Exception
	 */
	public static DynaBeanMap getTDepartmentByUpdate(Connection con, String departmentName, Integer departmentNo) throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select DEPARTMENT_NO from T_DEPARTMENT where DEPARTMENT_NAME = ? and DEPARTMENT_NO <> ?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, departmentName);
		query.setLong(2, departmentNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMap("T_DEPARTMENT", con);
	}
}
